//
//  PKReadWebViewController.m
//  PianKe
//
//  Created by lanou on 15/10/14.
//  Copyright (c) 2015年 李伟伟. All rights reserved.
//


#import "PKReadWebViewController.h"
#import "PKRequestManager.h"
#import "PKReadWebViewModel.h"
#import "NSString+Html.h"
@interface PKReadWebViewController ()
@property(nonatomic,strong)PKReadWebViewModel *model;
@property(nonatomic,strong)UIWebView *webView;
@end

@implementation PKReadWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 70, SCREEN_WITDTH, SCREEN_HEIGHT-70)];
    [self.view addSubview:_webView];
//    _webView.scrollView.contentSize = CGSizeMake(SCREEN_WITDTH, CGFloat height);
    [self requestData];
    
    
}

-(void)requestData
{
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"contentid"]= self.contentid;
    parDic[@"client"]= @"1";
    parDic[@"deviceid"]= @"63A94D37-33F9-40FF-9EBB-481182338873";
    parDic[@"auth"]= @"Wc06FCrkoq1DCMVzGMTikDJxQ8bm3Mrm2NpT9qWjwzcWP23tBKQx1c4P0";
    parDic[@"version"]= @"3.0.2";
    
    [PKRequestManager requestWithType:POST urlString:@"http://api2.pianke.me/article/info" parDic:parDic finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        _model = [[PKReadWebViewModel alloc]init];
        [_model setValuesForKeysWithDictionary:dic[@"data"]];
        
        //        NSString *HtmlString = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_model.html]] encoding:NSUTF8StringEncoding];
        
        NSString *HtmlString = [NSString importStyleWithHtmlString:_model.html];
        
        [_webView loadHTMLString:HtmlString baseURL:[NSURL URLWithString:[NSBundle mainBundle].bundlePath]];
        
        
        
        
    } error:^(NSError *error) {
        NSLog(@"");
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
